<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>查找当前字符e在字符串中的所有位置</title>
</head>
<body>
    <script type="text/javascript">
        // 查找e在str中的所有的位置
        var str = 'He unfolded the map and set it on the floor'
        var arr = [];
        var pos = str.indexOf('e');
        console.log(pos);
        while(pos > -1){
            // 找到当前e字符对应的位置
            arr.push(pos);
            pos = str.indexOf('e',pos+1);
        }
        console.log(arr);
    </script>

</body>
</html>